import React from 'react';
import styles from './index.less';

import commonPkg from '@/utils/commonPkg';

const {
  classNames
} = commonPkg;


export default class extends React.Component {
  static defaultProps = {
    isZoom  : false,
    fileUrl : '',
    easymode: false,
    onLoad  : () => {},
  };
  componentDidMount = ()=>{
    this.dom.addEventListener('load', this.load);
  }
  componentWillUnmount = ()=>{
    this.dom.removeEventListener('load', this.load);
  }
  load = () => {
    setTimeout(()=>{
      this.props.onLoad()
    },1000)
  };
  render() {
    const { fileUrl,easymode,isZoom } = this.props
    var url = `https://view.officeapps.live.com/op/embed.aspx?src=${fileUrl}`
    if(easymode){
      url = `https://view.officeapps.live.com/op/embed.aspx?ui=zh-CN&easymode=true&src=${fileUrl}`
    }
    // url = `https://view.officeapps.live.com/op/view.aspx?wdAccPdf=0&wdEmbedFS=1&easymode=true&src=${fileUrl}`
    console.log(url)

    return (
      <div className={classNames([styles.container,{
        [styles.zoom]:isZoom
      }])}>
        <iframe 
          id={'FilePreview'}
          ref={(dom)=>{this.dom = dom}}
          src={url}
          width="100%"
          frameborder="0"></iframe>
      </div>
    );
  }
}
